﻿using System;
using System.Linq;

namespace FilterStudents
{
    class FilterStudents
    {
        static void Main(string[] args)
        {
            FilterStundentsByName();
            FilterStundentsByAge();
            SortStudents();
        }

        private static void SortStudents() 
        {
            var students = new[] 
            {
                new { firstName = "Kostadin", lastName = "Kostadinov", age = 21 },
                new { firstName = "Avraam", lastName = "Kostadinov",age = 19 },
                new { firstName = "Kostadin", lastName = "Shepardov",age = 28 },
                new { firstName = "Kostadin", lastName = "Avraamov",age = 28 }
            };

            var sortedStudents = students.OrderBy(student => student.firstName).
                ThenByDescending(student => student.lastName);
            foreach (var student in sortedStudents)
            {
                Console.WriteLine(student);
            }
        }

        private static void FilterStundentsByAge() 
        {
            var students = new[] 
            {
                new { firstName = "Kostadin", lastName = "Kostadinov", age = 21 },
                new { firstName = "Avraam", lastName = "Kostadinov",age = 19 },
                new { firstName = "Kostadin", lastName = "Shepardov",age = 28 },
                new { firstName = "Kostadin", lastName = "Avraamov",age = 28 }
            };

            var querryResultAge =
                from student in students
                where student.age >= 18 && student.age <= 24
                select student;

            foreach (var student in querryResultAge)
            {
                Console.WriteLine("{0} {1}", student.firstName, student.lastName);
            }
        }

        private static void FilterStundentsByName()
        {
            var students = new[] 
            {
                new { firstName = "Kostadin", lastName = "Kostadinov", age = 21 },
                new { firstName = "Avraam", lastName = "Kostadinov",age = 19 },
                new { firstName = "Kostadin", lastName = "Shepardov",age = 28 },
                new { firstName = "Kostadin", lastName = "Avraamov",age = 28 }
            };

            var querryResultName =
            from student in students
            where student.firstName.CompareTo(student.lastName) < 0
            select student;

            foreach (var student in querryResultName)
            {
                Console.WriteLine(student);
            }
        }
    }
}
